package com.gitee.cnlongdb.test.busitest;

import java.util.Date;

import com.gitee.cnlongdb.server.transaction.actuator.LongdbTransactionActuator;
import com.gitee.cnlongdb.test.busitest.LongDbTest;

public class TransactionTtest {

	public void insert(String name) {
		
		System.out.println("执行insert方法..." + name);
		
		// 向表中插入数据
		TtestEntity object = new TtestEntity();
		Integer id = 123;
		object.setId(id.toString());
		object.setCode(id.toString());
		object.setName(name);
		object.setAge(id);
		object.setCreateDate(new Date());
		object.setBytes(("ABCDEFGabcdefg，哈哈，数字是："+id).getBytes());
		try {
			LongDbTest.longDbServer.insert(object);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		
//		int a = 2/0;
		int a = 0/2;
		System.out.println("a: " + a + "; [" + Thread.currentThread().getName() + "]");
		
	}
	
	public static void main(String[] args) {
		
		TransactionTtest test = new TransactionTtest();
		
		String name = "张三";
		LongdbTransactionActuator.transactionManager(
			() -> {
				test.insert(name);
				return null;
			}
		);
		
//		new Thread(new Runnable() {
//			@Override
//			public void run() {
//				String name2 = "李四";
//				LongdbTransactionActuator.transactionManager(
//					() -> {
//						test.insert(name2);
//						return null;
//					}
//				);
//				System.out.println();
//			}
//		}).start();
		
	}
	
}
